<template>
  <div class="city">
    <tabbar>
      <div slot="left">
        <i class="icon"></i>
      </div>
      <div slot="center">{{$store.state.cityname}}</div>
      <div slot="right">切换城市</div>
    </tabbar>
    <div class="search">
      <div>
        <input type="text" v-model="value" />
      </div>
      <div @click="search">提交</div>
    </div>
    <div v-if="haslocal">
      <p>搜索历史</p>
      <div>
        <ul>
          <li>法法</li>
        </ul>
      </div>
    </div>
    <div v-else>
      <div
        class="address"
        v-for="(item,index) in searchdata"
        :key="index"
        @click="gohome(item.name,item.geohash)"
      >
        <div>{{item.name}}</div>
        <div>{{item.address}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import http from "../../network/request";
import tabbar from "../../components/tabbar.vue";
export default {
  data() {
    return {
      value: "",
      haslocal: true,
      searchdata: [],
    };
  },
  components: {
    tabbar,
  },
  methods: {
    search() {
      http({
        url: `/v1/pois?city_id=${this.$store.state.cityid}&keyword=${this.value}`,
      }).then((res) => {
        // console.log(res);
        this.searchdata = res.data;
        this.haslocal = false;
      });
    },
    gohome(address, geohash) {
      let msg = [address, geohash];
      console.log(msg);
      this.$store.commit("getaddress", msg);
      //
      this.$router.push(`/home?geohash=${geohash}`);
    },
  },
  beforeDestroy() {
    this.haslocal = true;
  },
};
</script>

<style>
</style>